#define DEBUG
#include <cstdio>

using namespace std;

const int maxn=300;

void sort(int *a, int *b, int l, int r) {
  int i=l, j=r, mid=a[(l+r)/2], temp;
  for (; i<=j; ) {
    for (; a[j]>mid; j--);
    for (; a[i]<mid; i++);
    if (i<=j) {
      temp=a[i], a[i]=a[j], a[j]=temp;
      temp=b[i], b[i]=b[j], b[j]=temp;
      i++, j--;
    }
  }
  if (i<r) {
    sort(a, b, i, r);
  }
  if (j>l) {
    sort(a, b, l, j);
  }
}

long long solve(int dep, int l, int r, int fa, int *k, int *v) {
}

int main() {
  freopen("tree.in", "r", stdin);
  freopen("tree.out", "w", stdout);

  static int k[maxn+1], v[maxn+1];
  int n;
  scanf("%d", &n);
  for (int i=1; i<=n; i++) {
    scanf("%d %d", k+i, v+i);
    if (k[i]==1) {
      printf("-1");
      return 0;
    }
  }

  sort(k, v, 1, n);
  printf("%lld", solve(1, 1, n, n, k, v));

  fclose(stdin);
  fclose(stdout);
  return 0;
}
